package com.tedu.bill.demo7;

/**
 * Author：毕龙
 * Date: 2024/4/16 19:26
 */
public class TestPolymorphism {
    public static void main(String[] args) {
        //多态
        //父类的引用 子类的实例对象
        Pet p1 = new Dog();
        p1.play();
        Pet p2 = new Cat();
        p2.play();
        //创建人类对象
        Person zirong = new Person();
        //多态的体现 父类的引用
        Pet p3 = zirong.buy(10000);
        //向下转型
        //单独使用子类方法
        Dog dog = (Dog)p3;
        dog.eat();
        //将p3转化为人类
        //Inconvertible types; cannot cast 'com.tedu.bill.demo7.Pet' to 'com.tedu.bill.demo7.Person'
        //JVM编译时判断是否继承了Pet
        //Person person = (Person)p3;
        Cat cat = (Cat)p3;

        zirong.game(p3);
        Pet p4 = zirong.buy(1000);
        zirong.game(p4);
    }
}
